import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vite.dev/config/
export default defineConfig({
  plugins: [vue(), {
    name: 'fix-require-dayjs',
    apply: 'build',
    generateBundle(_, bundle) {
      // 遍历所有输出文件
      Object.keys(bundle).forEach(fileName => {
        if (bundle[fileName].type === 'chunk') {
          // 替换所有require调用
          bundle[fileName].code = bundle[fileName].code
            .replace(/require\(['"]dayjs.*['"]\)/g, '(window.dayjs || {})');
        }
      });
    }
  }],

})
